Skip to content

Star Fox (0400E88025B1A000) plays on the Mac: VZIP shaders, TXD and handle-pair translation, SDK 21 services and audio - #1259

Closed
webdz9r wants to merge 11 commits into
seedds:mainfrom
webdz9r:starfox-bringup
Closed

webdz9r wants to merge 11 commits into
seedds:mainfrom
webdz9r:starfox-bringup

Conversation

@webdz9r

@webdz9r webdz9r commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Star Fox (0400E88025B1A000, update v131072, SDK 21.4.4, NVN2 with DLSS) plays on the Mac: the title, the prologue cinematic and the tutorial flight, 7 minutes at 60 fps with sound. Its profile, tables and note are in dm/games/0400E88025B1A000/ (note); the game is in the games table and the README gallery.

What the host and the tools needed, all general, each with its reference entry:

  • Shader split: the engine's VZIP archive with LZ4-chained members, the GLSLC wrapper of each shader binary, and the NDSR networks embedded in VIPR containers (shaders.md).
  • Translator (chain change): a handle pair ORed sampler word first is ordered by c[2]'s tables: 62 of Star Fox's pixel shaders bound the sampler's word as the texture, a binding with no slot (A handle pair ORed sampler word first). DMSH_BINDLESS_TRACE prints what a refused handle is made of. The TXD handle fix this branch started with (0xf6c's reads of 281 pixel shaders, the fur shells) was taken in on main from PR 1261 meanwhile; Star Fox is added to that entry's Found on.
  • SDK 21 services: socket initialization against the host's bsd sessions and the C library's poll routed to the host (the game's HTTP thread aborted on a failed poll), GameChat queries from the title screen, the camera module's commands as a console with no camera (services.md).
  • SDK 21 audio: the hardware Opus decoder manager on the SDK's software decoders, and output streams on the host's AudioOut, including a stream object opened again after a focus change (audio.md).
  • nvnDlssNetworkResize (rendering.md).
  • NSP script: a NUP whose update package carries no control data takes the base package's name and icon.

Open, in the note: 3 shaders that do not translate (opcodes 0x925 and 0x21b; main's surface-atomic and TLD4 changes took the other 10 of the 13 the branch started with), one compute shader whose sampler words lie outside the decoded table, a one-off GPU hang the game recovered from, the memory split not measured, iOS not tested.

Checked

  • Tests: make -C dm/host/tests GAME=0400E88025B1A000 run (143 checks), make -C dm/gfx/tests GAME=0400E88025B1A000 run (all suites 0 failed), DM_GAME=0400E88025B1A000 python3 -m unittest discover -s dm/tools/tests (1,116 tests, 23 skipped), the docs and chain-header tests.
  • Games run: Star Fox v131072, a 7-minute session with a controller through the title, the prologue cinematic and the tutorial flight, frame time p50 16.67 ms / p95 17.1 ms, with sound; scripted runs of the prologue for screenshots and audio levels, and scripted window focus changes (DM_OE_SCRIPT).
  • Devices and OS: Apple M5 Max, macOS 27.0.1. iOS not tested.
  • Regression, Apple M5 Max, macOS 27.0.1, Xcode 27.2:
    • scripts/regress.py check --games 0400E88025B1A000 against main cc60a0c1 (chain 7a8a6262ad3a → df2e21c7b7dd): CHANGED, 2853/2856 → 2853/2856 shaders, 0 newly failing, 0 interface regressions, 275 shaders changed (MSL, reflection and variants): the shaders whose c[2] handle pairs the sampler-word ordering renames, the 62 sampler-first pairs and the 213 handles chosen among phi inputs; 3 fail in both (opcodes 0x925, 0x21b); the bindless accesses the translator deleted go from 62 to 0. The harness needed one change for a game the baseline does not have (its profile taken from the candidate), in its own commit.
    • scripts/regress.py chain --games 0400C3F00006E000 (Mario Kart World, the static checks, against main 5ae0d9ae before the rebase): PASS, 11603/11604 → 11603/11604, 0 changed MSL, 0 interface regressions.
    • Donkey Kong Bananza and Mario Tennis Fever were not run through the harness (their 58,000 shaders translated twice is an hour of machine time); the chain change is in the translator's texture emitter and bindless elimination, which the Mario Kart World comparison exercises.
  • Not checked: the other Switch 2 games' apps were not rebuilt with the new chain beyond the regression harness; iOS.

Docs

  • The findings are in the game note and the reference entries (services, audio, rendering, shaders), and python3 dm/tools/docs_symptoms.py was run
  • A chain tool changed: dmsh_chain.py --header was run and dm/gfx/nvn/dmsh_chain.h is part of the change
  • No game files, keys or data extracted from a game in the change or the attachments

@github-actions github-actions Bot added host The Horizon host: SVCs, services, threads, memory (dm/host) nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) packing Building an IPA or a Mac app: the NSP script, extraction, the shader split, the packers tools Tools and scripts (dm/tools, scripts) docs Documentation shader chain The shader translation chain (DMSH_CHAIN): a change rebuilds every game's shaders game: 0400E88025B1A000 A game profile new game Adds a game profile that main does not have yet labels Nov 4, 2026
@webdz9r

webdz9r commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Note on overlap: #1254 implements the same two SDK 21 audio pieces (the hardware Opus decoder manager and output streams) for Xenoblade Chronicles 2, in the same files (hle_codec.c, hle_audio.c). This PR's version was written for Star Fox (Wwise 2024.1) and adds two things the other does not have: a stream object opened again without a close (Star Fox opens a new stream each time its window regains focus, and a quick loss and regain opens the same object twice, which starved the fed stream), and the audio diagnostics (the peak level handed to the device on the periodic callback line, the level of what the game writes, the first gain calls). Happy to rebase this onto #1254's version of those two files if that one goes in first.

@webdz9r
webdz9r force-pushed the starfox-bringup branch 2 times, most recently from 873d397 to ca5173d Compare November 5, 2026 00:46
@webdz9r

webdz9r commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

The clang-tidy ratchet's failure here is main's: main's own lint-c run at 9507c22 (https://github.com/seedds/nxnative/actions/runs/41932280822) reports the same five file/check pairs above the baseline (t_pso_skey.m, hle_vk.m, hle_jit.c, hle_oe.c's fread, web_apple.m) and the same ArrayBound entry below it; none of those files changes in this PR beyond six added lines in hle_oe.c that hold no fread. The Python ratchet's two findings in main's own files (settings.py B023, test_split_linkdata.py's optional) are fixed in this PR's lint commits, so that job is green here.

…rough a uniform-register handle, and a handle pair ORed sampler word first

Star Fox (0400E88025B1A000, SDK 21.4.4, NVN2) keeps every shader in data.zip, a zip with a VZIP preamble whose members are chains of LZ4 blocks (each block's dictionary is the previous one), each member a GLSLC output (magic 0x19866891, the Ampere code area with its SPH, then an NVN2 control section). Two NDSR upscaler networks are embedded in VIPR resource containers. shader_split.py reads all of these (viper_zip_member, viper_shader, the VIPR scan in scan_blob), with a test of synthetic members.

Of its 2,828 shaders, 294 did not translate: "Ampere instruction f6c is not implemented". 0xf6c is TXD with its texture handle in a uniform register at bits 40..46, the form 0xf60 is for TEX; the translator knew TXD only as 0xb6c. It is registered and decoded as 0xf60's handle with 0xb6c's fields. The handle has to lead the bindless operation's sources: a first version put only the coordinates there, so the bindless elimination took a float coordinate for the handle, logged "Failed to find handle source for bindless access of type texture2DArray" for 765 reads in 281 pixel shaders and replaced each read by 0: the characters' fur shells drew as black scribbles.

62 more pixel shaders OR the separate sampler word before the texture word (c[2][0x5c0] | c[2][0x248]); the elimination took the first operand as the texture, which named the sampler's word (slot 0x170 of the separate sampler table) as a texture binding that has no slot, and five of them failed at load. A pair of c[2] words is now ordered by the table each lies in (dmsh_abi.h DMSH_C2_SAMP), in the plain OR and among a phi's candidates, and a bare sampler word is no texture candidate. DMSH_BINDLESS_TRACE=1 on a dmsh_xlate job prints what a refused handle is made of.

Chain change (dmsh_chain.h). Checked on Star Fox's 2,856 shaders: 2,843 translate, no dropped reads; fur and faces right in the prologue and the tutorial.
…d sessions, libc poll on the host, GameChat queries, the camera module's commands

Star Fox's HTTP thread aborted a few seconds after boot, intermittently: the SDK's socket initialization was answered by a stub, so the game's poll on its sockets returned -1 with EFAULT, which only EINTR survives. nn::socket::Initialize now runs the SDK's own code against the host's bsd:u, bsd:s and bsd:a sessions, its overloads (GetPeerName, Shutdown, Read, Write, GetHostEntByName, SetAllocator) are hooked, and the C library's poll is routed to the host, which idles on descriptors it does not know instead of failing. nifm's GetCurrentIpConfig answers offline.

The title screen asks nn::chat for the chatting user and the room (a null read in GetChattingUid): 24 GameChat calls answer as no chat, no room, no sharing. The game's own camera module (subsdk3) sends commands to the camera service: Initialize and Finalize succeed, the connection event is bound, QueryDeviceConnection and the rest answer 0x7c4 (no camera plugged in), and the applet's camera resource and DestroyCameraContext are no-ops; earlier answers (a failing Initialize, 0xdc4) made the module abort or read null. The present-photographed-contents and in-store demo calls are answered too.

Checked: make -C dm/host/tests run (the camera expectations in t_sf updated), Star Fox through the title, the prologue and the tutorial without the abort over several sessions.
…oftware decoders, output streams on the host's AudioOut

Star Fox decodes its voices through SDK 21's HardwareOpusDecoderManager: the manager, its decoders, the enqueue / execute / dequeue cycle and the counts are answered by the host, each decode done with the SDK's software decoder and the manager's event signalled; the decoder list and the I/O buffers are sized from the manager's parameters (128 decoders, 255 buffers here). DM_OPUS_LOG=1 logs each call.

Its sound goes through nn::audio::OutputStreamType: the default virtual output device is the built-in speaker, and a stream is a host AudioOut of the same channel count: each WriteOutputStream becomes a PCM block (float, 24- and 32-bit samples converted to 16-bit), the released blocks free their frames and signal the stream's event, Start / Stop / Purge / Close map to the AudioOut's, SetOutputStreamGain is the volume. A gain set on a stream object the game never opened is ignored. The game opens a new stream each time its window regains focus and never closes the old one; a quick loss and regain made it open the same object twice, which made a second AudioOut under the same key and starved the fed stream (silence after switching windows): an open object's earlier output is closed first, stopped and drained before the AudioOut goes.

Diagnostics: the periodic device-callback line ends with the peak sample handed to the device, WriteOutputStream logs the level of what the game writes early on and then every 2,000 writes, and the first gain calls are logged.

Checked: make -C dm/host/tests run; Star Fox's title, prologue and tutorial with sound, scripted focus changes (DM_OE_SCRIPT) with the stream fed and audible after each regain.
Star Fox calls nvnDlssNetworkResize, which the host did not know (an unimplemented NVN entry stops the game). It is answered as a success, logged once; the MetalFX path sizes its upscaler from the frame it is given.
Star Fox's NUP holds the base game and one update; its profile registers the update, so only the update is extracted, and its package carries no control data (no NACP, no icon): the Mac app had no icon. The base package's control data is now written to extract/v0 beside the versions (pack_nup.control, without the base's RomFS) and used for the app's name and icon when the packed version has none.

Checked: python3 -m unittest dm.tools.tests.test_nsp_nup; Star Fox.app with its icon.
A Switch 2 game, update v131072 over the base game, SDK 21.4.4, NVN2 with DLSS, its own engine with Wwise 2024.1. The profile takes Fire Emblem Fortune's Weave's memory split as a starting point, modules main subsdk0 subsdk3 sdk, data.zip as the RomFS marker and the one shader group; its tables are the split's 2,856 shaders.

Plays on the Mac (M5 Max): the title, the prologue cinematic and the tutorial flight, 7 minutes with a controller at 60 fps with sound. The note lists what the host needed (all general, in the reference entries), how to drive it, and what is open: 13 shaders that do not translate (SURED form 0310e000, opcodes 0x925, 0xf63, 0x21b), one compute shader whose sampler words lie outside the decoded table, a one-off GPU hang the game recovered from, the memory split not measured, iOS not tested.
…ndidate for the baseline's chain

A bring-up PR adds the game's profile, so the baseline revision has no dm/games/<id> and the check stopped with FileNotFoundError on copying it. The baseline's chain now translates such a game's shaders with the candidate's profile (the same inputs, so the comparison is of the chains alone). Found on Star Fox's check against main: 2562/2856 → 2843/2856 shaders, 281 newly building, 0 newly failing.
…choice filter binds its row number

The Python ratchet (ruff 0.17.2) flagged two findings beyond the baseline: `fz` imported and unused in test_split_viper.py, and in dm/games/settings.py the `offered` function defined inside the rows loop reading the loop variable `n` (B023; the call is immediate, so the behaviour was right; it is bound as a default argument now). Checked: dm/tools/lint_python.py --against origin/main with the pinned tools, 0 new; the launcher settings and Mac app tests.
…r Fox down to 3 shaders that do not translate

main registered 0xf6c (TXD), 0xf63 (TLD4) and the 0x364 / 0x367 forms through one rule while this branch registered 0xf6c on its own: the duplicate registration is dropped and main's form kept, with this branch's handle-first TXD sources and the sampler-word ordering on top. The chain binaries, lock and header are rebuilt from the merged source (chain 34d393503178).

On it Star Fox translates 2,853 of 2,856 shaders: main's surface-atomic forms and TLD4 take 10 of the 13 that failed, leaving opcodes 0x925 (2) and 0x21b (1); the compute shader dispatched at the prologue's load is among those translating now. The note and the TXD entry say so. Checked: the two test shaders of the TXD and handle-pair entries, make -C dm/host/tests run (143 checks), the chain-header, docs and split tests, dm/tools/lint_python.py (0 new).
main's new test_split_linkdata.py iterates linkdata_jobs' result, which can be None (no index): pyright reportOptionalIterable, one finding beyond the ratchet's baseline on this branch. An assertion that the jobs are there narrows it. Checked: the test, dm/tools/lint_python.py --against origin/main with the pinned tools (0 new).
…ox joins its entry; the chain rebuilt on the merged source

main took the same TXD handle-first fix in from PR 1261 with its own entry, so this branch's copy of the change and its entry go, and Star Fox (281 pixel shaders, the fur shells) is added to that entry's Found on, with the DMSH_BINDLESS_TRACE note. The sampler-word ordering stays this branch's. The chain binaries, lock and header are rebuilt on the merged translator (chain 9a167b685c99, main's float-comparison change included).

Checked: Star Fox translates 2,853 of 2,856 shaders as before, the two test shaders of the entries, make -C dm/host/tests run (143 checks), the chain-header, docs and split tests, dm/tools/lint_python.py (0 new).
@seedds

seedds commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Landed as 67f1d00, reworked, with you credited as co-author. Thank you: the VZIP and shader wrapper split, the sampler-first handle pairs, GameChat, the camera answers and the profile are yours. Checked on the game's v131072 on an M4 Pro: title, prologue and the start of the tutorial, with sound.

What changed, each from the game's disassembly or a run:

  • Audio: taken from SDK 21's hardware Opus decoder manager and OutputStream #1254 instead. GetOutputStreamState here answered 0 for a started stream, where the SDK's 0 means not open. The game's close path (main+0xbce9754) stops a stream in state 2 and closes one in state 1, so it never closed one, which is why a stream seemed to be reopened on each focus gain. The host dies at more than 8 outputs, so it was not harmless. With 0 / 1 / 2 the game closes on focus loss and opens on regain; 14 rounds went by with the sound intact, and the double-open guard is gone. GetOutputStreamStatistics is a 24-byte result through x8.
  • 1002069a331ceded: its words are not outside the table. NVN2 compute's c[0] handles run textures, separate textures, separate samplers, images (control +0xb3 to +0xb6), and AMapC0 now maps them. The shader is dispatched in the prologue and loads now.
  • Sockets: nn::socket::internal::Initialize(int) is cut, with your poll route, so the bsd:* sessions are not needed. HIPC Close stays, because the camera session sends one.
  • Dropped: the TXD change (on main already), the audio diagnostics in the render callback, DM_OPUS_LOG, and nup_base_control (the NUP here has no NACP or icon in its base package; if yours does, a small PR with that is welcome).

Open, in the game's note: all 3D targets stay at 768x432 (the dynamic resolution minimum, with 6 to 11 ms of GPU time here; gpu_timestamps segment changes nothing), and 3 shaders do not translate. I have not watched flying under input on this Mac, so your controller session is the evidence for that; a retest on the landed commit would help. Mario Kart World 1.8.0 has not run with the new camera answers.

@seedds seedds closed this Nov 5, 2026
@webdz9r
webdz9r deleted the starfox-bringup branch November 5, 2026 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation game: 0400E88025B1A000 A game profile host The Horizon host: SVCs, services, threads, memory (dm/host) new game Adds a game profile that main does not have yet nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) packing Building an IPA or a Mac app: the NSP script, extraction, the shader split, the packers shader chain The shader translation chain (DMSH_CHAIN): a change rebuilds every game's shaders tools Tools and scripts (dm/tools, scripts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants